package com.china08.yxyapi.model.questionbank;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class YxyQuesBanQuestType1_2_3Model extends YxyQuesBankModel {

    private List<Choose> quesOptions;// 试题选项

    private Choose quesAnswer;// 试题答案

    public YxyQuesBanQuestType1_2_3Model() {
    }

    public class Choose {
        String options;
        String body;
        // 排序
        Integer no;

        public String getOptions() {
            return options;
        }

        public void setOptions(String options) {
            this.options = options;
        }

        public String getBody() {
            return body;
        }

        public void setBody(String body) {
            this.body = body;
        }

        public Integer getNo() {
            return no;
        }

        public void setNo(Integer no) {
            this.no = no;
        }
    }

    public List<Choose> getQuesOptions() {
        return quesOptions;
    }

    public void setQuesOptionsSave(Map<String, String> map) {
        List<Choose> list = new ArrayList<YxyQuesBanQuestType1_2_3Model.Choose>();
        int i = 1;
        for (Map.Entry<String, String> entry : map.entrySet()) {
            Choose choose = new Choose();
            choose.options = entry.getKey();
            choose.body = entry.getValue();
            choose.no = i;
            list.add(choose);
        }
        this.quesOptions = list;
    }

    public Choose getQuesAnswer() {
        return quesAnswer;
    }

    public void setQuesAnswerSave(String quesAnswer, int quesType) {
        if (quesType == 1) {
            // 单选
            Choose choose = new Choose();
            choose.options = quesAnswer;
            choose.body = "";
            choose.no = 1;
            this.quesAnswer = choose;
        } else if (quesType == 2) {
            // 多选
            String[] answersStr = quesAnswer.split(",");
            String answer = "";
            for (String string : answersStr) {
                if (string.matches("[a-zA-Z]")) {
                    answer = answer + string;
                }
            }
            Choose choose = new Choose();
            choose.options = answer;
            choose.body = "";
            choose.no = 1;
            this.quesAnswer = choose;
        } else if (quesType == 3) {
            // 判断
            Choose choose = new Choose();
            choose.options = quesAnswer;
            choose.body = "";
            choose.no = 1;
            this.quesAnswer = choose;
        }

    }

    public void setQuesOptions(List<Choose> quesOptions) {
        this.quesOptions = quesOptions;
    }

    public void setQuesAnswer(Choose quesAnswer) {
        this.quesAnswer = quesAnswer;
    }

}
